﻿#pragma once
#if defined(_MSC_VER)
    #define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <memory> // 引入智能指针
#include <vector> // 引入动态数组
#include <string> // 引入字符串，用于输出（有 << 运算符重载）
using std::cout; // 命名空间 std 中的 cout 使用声明
using std::endl;
using std::string;
//#include <utility> // 引入 pair 类型，用于返回多个值，可以使用 make_tuple 构造 tuple 对象
//#include <tuple> // 引入 tuple 类型
//#include <functional> // 引入函数对象库，里面有 tuple
//#include <algorithm> // 引入算法
//#include <cmath> // 引入数学函数库
//#include <cstdlib> // 引入标准库
//#include <ctime> // 引入时间库
//#include <cassert> // 引入断言库
//#include <cstring> // 引入字符串库
//#include <cstdio> // 引入输入输出库

class Coordinate {
private:
    double x, y;
public:
    Coordinate()
        : x(0), y(0) {
        cout << "Create Coordinate successfully!" << endl; }
    /*Coordinate(const Coordinate& c)
        : x(c.x), y(c.y) {
        std::cout << "Create Coordinate and copy x, y successfully!" << std::endl;
    }
    Coordinate(double x = 0, double y = 0)
        : x(x), y(y) {
        std::cout << "Create Coordinate and set x, y successfully!" << std::endl;
    } */
    double getX() const { return x; }
    double getY() const { return y; }
    void setX(double x) { this->x = x; }
    void setY(double y) { this->y = y; }
    void print() const { cout << "Coordinate: " 
        << "(" << x << ", " << y << ")" << endl; }

    ~Coordinate() { cout << "Destroy Coordinate successfully!" << endl; }
};

class ScopedPtr {
private:
    Coordinate* s_ptr; // 类指针
public:
    ScopedPtr()
        : s_ptr(nullptr) { cout << "Create ScopedPtr successfully!" << endl; }
    ScopedPtr(Coordinate* c_ptr)
        : s_ptr(c_ptr) { cout << "Create ScopedPtr and set pointer successfully!" << endl; }
    ~ScopedPtr()
    {
        if (s_ptr) {
            delete s_ptr;
            s_ptr = nullptr;
        }
        cout << "Destroy ScopedPtr successfully!" << endl;
    }

    Coordinate* operator->() { // 重载 -> 运算符
        return s_ptr;
    }

    const Coordinate* operator->() const { // 重载 const -> 运算符
        return s_ptr;
    }
};

extern void test_copy_fuc();
extern void test_template();



// 宏定义
#define print_start(str) std::cout << " ----------------- " << str << " Start ------------------------\n";
#define print_end(str) std::cout << " ----------------- " << str << " End ------------------------\n\n\n";